/* This program is free software. It comes without any warranty, to
 * the extent permitted by applicable law. You can redistribute it
 * and/or modify it under the terms of the Do What The Fuck You Want
 * To Public License, Version 2, as published by Sam Hocevar. See
 * http://sam.zoy.org/wtfpl/COPYING for more details. */ 
package de.rockon.fuzzy.controller.gui.propertyeditor;

import java.awt.Component;
import java.awt.FlowLayout;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;

import de.rockon.fuzzy.controller.model.enums.ColorType;

public class ColorBoxRenderer extends DefaultListCellRenderer {
	private static final long serialVersionUID = -3490153922813551034L;
	private JPanel colorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
	private JLabel colorBoxLabel = new JLabel("     ");

	@Override
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		Component comp = super.getListCellRendererComponent(list, ((ColorType) value).toString(), index, isSelected, cellHasFocus);
		colorPanel.removeAll();
		colorPanel.setBackground(comp.getBackground());
		colorBoxLabel.setOpaque(true);
		colorBoxLabel.setBackground(((ColorType) value).getColor());
		colorPanel.add(colorBoxLabel);
		colorPanel.add(comp);

		return colorPanel;
	}
}